﻿Imports System.ComponentModel
'Imports System.Collections.ObjectModel
Public Class PhotoPages
    Implements INotifyPropertyChanged

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) _
        Implements INotifyPropertyChanged.PropertyChanged

    Private Const PPP = 18 'Pictures Per Page

    Private _photos As List(Of Photo)
    Private _pagenumber As Integer

    Public Property Photos() As List(Of Photo)
        Get
            Return _photos
        End Get
        Set(ByVal value As List(Of Photo))
            _photos = value
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Photos"))
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("NumberOfPages"))
        End Set
    End Property

    Public Property PageNumber() As Integer
        Get
            Return _pagenumber
        End Get
        Set(ByVal value As Integer)
            If value <> _pagenumber Then
                _pagenumber = value
                RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("PageNumber"))
                RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("PhotoPage"))
            End If
        End Set
    End Property

    Public ReadOnly Property NumberOfPages() As Integer
        Get
            Dim count As Integer = _photos.Count \ 18
            If _photos.Count Mod 18 > 0 Then count += 1
            Return count
        End Get
    End Property

    Public ReadOnly Property ItemsPerPage() As Integer
        Get
            Return PPP
        End Get
    End Property

    Public ReadOnly Property PhotoPage() As List(Of Photo)
        Get
            Dim output As New List(Of Photo)
            For i As Integer = PPP * _pagenumber To (PPP * _pagenumber) + PPP - 1
                If (i < Photos.Count) And (i >= 0) Then
                    output.Add(Photos.Item(i))
                Else
                    Exit For
                End If
            Next
            Return output
        End Get
    End Property

End Class
